package com.bds.btcdc;

import com.alibaba.fastjson.JSONObject;
import com.bds.btcdc.api.TradeService;
import com.bds.btcdc.api.impl.TradeServiceImpl;
import com.bds.btcdc.api.model.Result;
import com.bds.btcdc.service.TransactionRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

import com.bds.btcdc.util.SpringContextHolder;
import org.springframework.context.annotation.Bean;
import org.springframework.remoting.caucho.HessianServiceExporter;


@SpringBootApplication
public class StartApp {

	@Autowired
	private TradeService tradeService;

	public static void main(String[] args) {

		SpringApplication springApplication = new SpringApplication(StartApp.class);
		springApplication.addListeners(new AppStartupList());
		ApplicationContext context = springApplication.run(args);
		SpringContextHolder.setApplicationContext(context);
//		TradeServiceImpl tradeService = (TradeServiceImpl)context.getBean("TradeService");
//		Result okex = tradeService.getAccount(54L);
//		System.out.println("获取资产情况："+JSONObject.toJSONString(okex));
//		Result result = tradeService.makeOrder(54, "ZB", "xrp_qc", "1", "5.38", "1");
//		System.out.println("委托下单结果："+JSONObject.toJSONString(result));
		TransactionRecordService tradeService = (TransactionRecordService)context.getBean("transactionRecordService");
		tradeService.createTable();
	}

	//发布服务
	@Bean(name = "/TradeService")
	public HessianServiceExporter accountService() {
		HessianServiceExporter exporter = new HessianServiceExporter();
		exporter.setService(tradeService);
		exporter.setServiceInterface(TradeService.class);
		return exporter;
	}
}
